package com.gitee.wsl.compose.ui.base


import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.toggleable
import androidx.compose.material3.Checkbox
import androidx.compose.material3.CheckboxColors
import androidx.compose.material3.CheckboxDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TriStateCheckbox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.state.ToggleableState
import androidx.compose.ui.unit.dp

object Checkbox {}


@Composable
fun Checkbox.Row(checked: MutableState<Boolean>,
                 hit:String = "Option",
                 modifier: Modifier = Modifier,
                 enabled: Boolean = true,
                 colors: CheckboxColors = CheckboxDefaults.colors(),
                 interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
){
    androidx.compose.foundation.layout.Row(
        Modifier
            .toggleable(
                value = checked.value,
                role = Role.Checkbox,
                onValueChange = { checked.value = !checked.value }
            )
            .padding(16.dp)
            .fillMaxWidth()
    ) {
        Text(text = hit, Modifier.weight(1f))
        Checkbox(checked = checked.value, onCheckedChange = null,modifier, enabled, colors)
    }
}

@Composable
fun Checkbox.TriState(
    state: ToggleableState,
    onClick: (() -> Unit)?,
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    colors: CheckboxColors = CheckboxDefaults.colors(),
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }
) = TriStateCheckbox(state, onClick, modifier, enabled, colors, interactionSource)

